package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Customer;
import com.ruoyi.system.service.ICustomerService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 顾客信息Controller
 * 
 * @author ruoyi
 * @date 2025-09-25
 */
@RestController
@RequestMapping("/customer")
public class CustomerController extends BaseController
{
    @Autowired
    private ICustomerService customerService;

    /**
     * 查询顾客信息列表
     */
    @RequiresPermissions("system:customer:list")
    @GetMapping("/list")
    public TableDataInfo list(Customer customer) {
        //开启分页
        startPage();
        List<Customer> customerList = customerService.customerList(customer);
        System.out.println(customerList);
        return getDataTable(customerList);
    }

    /**
     * 获取顾客信息详细信息
     */
    @RequiresPermissions("system:customer:query")
    @GetMapping(value = "/{customerId}")
    public AjaxResult getInfo(@PathVariable("customerId") Long customerId)
    {
        Customer customer = customerService.getCustomerByid(customerId);
        return AjaxResult.success(customer);
    }

    /**
     * 新增顾客信息
     */
    @RequiresPermissions("system:customer:add")
    @Log(title = "顾客信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Customer customer)
    {
        boolean b = customerService.addCustomer(customer);
        return b?AjaxResult.success():AjaxResult.error();
    }

    /**
     * 修改顾客信息
     */
    @RequiresPermissions("system:customer:edit")
    @Log(title = "顾客信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Customer customer)
    {
        boolean b = customerService.updateCustomer(customer);
        return b?AjaxResult.success():AjaxResult.error();
    }

    /**
     * 删除顾客信息
     */
    @RequiresPermissions("system:customer:remove")
    @Log(title = "顾客信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerIds}")
    public AjaxResult remove(@PathVariable(value = "customerIds") Long customerId)
    {
        boolean b = customerService.deleteCustomerById(customerId);
        return b?AjaxResult.success():AjaxResult.error();
    }
}
